﻿using Budget.Service;
using System;
using Budget.Model;
using Microsoft.AspNetCore.Mvc;

namespace Budget.Manage.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class AdminController: ControllerBase
    {
        
        readonly AdminService service = new AdminService();

        [HttpGet]
        public Admin Login(string account,string password)
        {
            Admin admin = service.GetAdmin(account);
            if (admin ==null)
            {
                throw new ArgumentException("用户不存在。");
            }
            if (admin.Account != account || admin.Password != password)
            {
                throw new ArgumentException("用户名或密码错误。");
            }
            //var adminSession = Guid.NewGuid().ToString();
            //HttpContext.Current.Session[adminSession] = admin.Id;

            admin.Password = string.Empty;
            return admin;
        }
         
    }
}